# Inset figures with overlays # 3 April 2013 # NJG par.default <- par(no.readonly=TRUE) set.seed(102) #################################################### # create a stochastic increasing time series x <- 1:1000 y <- rgamma(1000,shape=2,scale=1) + 0.01*x ################################################### # select a time slice for plotting slice <- 300:450 # create the main graph par(mar=c(5,6,1,1)) plot(x[slice],y[slice],xlim=range(slice),col="gray",type="l", xlab="Time",ylab="Temperature", font.lab=2,cex.lab=1.5,las=1,ylim=range(y[slice])) ################################################################## #add par commands to strip margins, overplot, and place the inset par(new=TRUE) # overlay existing plot par(mar=c(0,0,0,0)) # strip out the margins for the inset plot par(fig=c(0.4,0.7,0.80,0.94)) # fig shrinks and places relative to figure region ################################################################# # separately create the inset graph plot(x,y,type="l",ann=FALSE) rect(slice[1],-1,slice[length(slice)],1000,col="gray",border=NA) box() lines(x,y) ######################################### par(par.default)